import {getMajorList, addMajor, delMajor, updateMajor, searchTitle,
  getInformList,createInform,updateInform,deleteInform,searchInformTitle,
  getSchoolDesc,createOrUpdateSchoolDesc,getSchoolHelp,createOrUpdateSchoolHelp,
  getSiteConfig,createOrUpdateSiteConfig
} from "@/api/portal"

const state = {majorList: null, informList: null,schoolDesc:null,schoolHelp:null,siteConfig:null};
const getters = {
  majorList: (state) => state.majorList,
  informList: (state) => state.informList,
  schoolDesc: (state) => state.schoolDesc,
  schoolHelp: (state) => state.schoolHelp,
  siteConfig: (state) => state.siteConfig,
}

const mutations = {
  setMajorList(state, data) {
    state.majorList = data
  },
  setInformList(state, data) {
    state.informList = data
  },
  setSchoolDesc(state, data) {
    state.schoolDesc = data
  },
  setSchoolHelp(state, data) {
    state.schoolHelp = data
  },
  setSiteConfig(state, data) {
    state.siteConfig = data
  }
}

const actions = {
  async setMajorList({commit}, param) {
    const {data} = await getMajorList(param);
    commit('setMajorList', data)
  },
  async addMajorList({commit}, param) {
    return await addMajor(param);
  },
  async delMajor({commit}, param) {
    return await delMajor(param);
  },
  async updateMajor({commit}, param) {
    return await updateMajor(param);
  },
  async searchTitle({commit}, param) {
    const {data} = await searchTitle(param);
    commit('setMajorList', data)
  },
  async getInformList({commit}, param) {
    const {data} = await getInformList(param);
    commit('setInformList', data)
  },
  async searchInformTitle({commit}, param) {
    const {data} = await searchInformTitle(param);
    commit('setInformList', data)
  },
  async createInform({commit}, param) {
    return  await createInform(param);
  },
  async updateInform({commit}, param) {
    return  await updateInform(param);
  },
  async deleteInform({commit}, param) {
    return  await deleteInform(param);
  },

  async getSchoolDesc({commit}, param) {
    const {data} = await getSchoolDesc(param);
    commit('setSchoolDesc', data)
  },
  async createOrUpdateSchoolDesc({commit}, param) {
    return  await createOrUpdateSchoolDesc(param);
  },

  async getSchoolHelp({commit}, param) {
    const {data} = await getSchoolHelp(param);
    commit('setSchoolHelp', data)
  },
  async createOrUpdateSchoolHelp({commit}, param) {
    return  await createOrUpdateSchoolHelp(param);
  },

  async getSiteConfig({commit}, param) {
    const {data} = await getSiteConfig(param);
    commit('setSiteConfig', data)
  },
  async createOrUpdateSiteConfig({commit}, param) {
    return  await createOrUpdateSiteConfig(param);
  },
}

export default {state, getters, mutations, actions};

